package com.Maykk.Demo08;

/**
 * @ClassName: Demo
 * @Description: TODO 引用构造器练习
 * @Author: MaykkStar@163.com
 */
interface PeopleBuilder {
    People runBuilder(String name);
}

class People {
    public String name;

    public People() {
    }

    public People(String name) {
        this.name = name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                '}';
    }
}

public class Demo {
    public static void main(String[] args) {
        // 匿名内部类
        PeopleBuilder p01 = new PeopleBuilder() {
            @Override
            public People runBuilder(String name) {
                return new People(name);
            }
        };
        System.out.println(p01.runBuilder("匿名内部类"));
        System.out.println("================================================");

        // 完整 Lambda
        PeopleBuilder p02 = name -> {
            return new People(name);
        };
        System.out.println(p02.runBuilder("完整 Lambda "));
        System.out.println("================================================");
        // 省略 Lambda
        PeopleBuilder p03 = name -> new People(name);
        System.out.println(p03.runBuilder("省略Lambda "));
        System.out.println("================================================");
        // 引用构造器
        PeopleBuilder p04 = (People::new);
        System.out.println(p04.runBuilder("引用构造器"));
    }
}
